package cn.ex;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

public class Ex7 {
    public static void main(String[] args) {
        String fp = "d:/users/oa/goods/24234xxxsfsf_22sf.jpg";
        //windows \\  /
        //linux /

        //linux
        fp = "/etc/usr/local/oa/abc.jpg";

        //windows
        //fp = "d:\\users\\crm\\upload\\yyyyy.jpg";

        if(fp.contains("\\")){
            fp = fp.replace("\\","/");
        }

        System.out.println(File.separator); //windows \\  linux /


        System.out.println(fp);

        //目录 //d:/users/oa/goods
        System.out.println(fp.substring(0,fp.lastIndexOf("/")));

        //文件名 24234xxxsfsf_22sf.jpg
        System.out.println(fp.substring(fp.lastIndexOf("/")+1));

        //扩展名
        System.out.println(fp.substring(fp.lastIndexOf(".")+1));

        //文件的基本名
        String fn = fp.substring(fp.lastIndexOf("/")+1);
        System.out.println(fn.substring(0,fn.lastIndexOf(".")));

        //更名 d:/users/oa/goods/24234xxxsfsf_22sf.jpg
        //更名 d:/users/oa/goods/uuid字符串.jpg
        //更名 d:/users/oa/goods/yyyyMMddHHmmss.jpg
        String u = UUID.randomUUID().toString();
        System.out.println(fp.replace(fn.substring(0,fn.lastIndexOf(".")),u));

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

        System.out.println(fp.replace(fn.substring(0,fn.lastIndexOf(".")),sdf.format(new Date())));
    }
}
